﻿using ClassEntities;
using Facade;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Edu_Examination
{
    public partial class frm_index : Form
    {
        tblSinhVien Session { get; set; }
        SuperFacade facade;
        public frm_index()
        {
            InitializeComponent();
            if (Session == null)
            {
                this.Hide();
                frm_login frm = new frm_login();
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    Session = frm.Bean;
                    loadInfo();
                    this.Show();
                }
                else
                {
                    Application.Exit();
                }
            }
        }
        void loadInfo()
        {
            txtGioitinh.Text = (string.IsNullOrEmpty(Session.Gioitinh) || Session.Gioitinh == "False" ) ? "Nữ" : "Nam";
            txtHoTen.Text = Session.Hoten;
            txtNgaySinh.Text = Session.Ngaysinh.ToShortTimeString();
            txtDiaChi.Text = Session.Diachi;
            txtDT.Text = Session.Dienthoai;
            txtEmail.Text = Session.Email;
            try { if (Session.ImgSV != null) pictureBox1.Image = convert((byte[])Session.ImgSV); }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }
        public Image convert(byte[] _byte)
        {
            Image newImage;
            using (MemoryStream stream = new MemoryStream(_byte))
            {
                newImage = System.Drawing.Image.FromStream(stream);
            }
            return newImage;
        }
        private void dockPanel2_Click(object sender, EventArgs e)
        {

        }

        private void btLichThi_Click(object sender, EventArgs e)
        {
            pnlControl.Controls.Clear();
            UC_LichThi lichthi = new UC_LichThi(Session);
            lichthi.Dock = System.Windows.Forms.DockStyle.Fill;
            pnlControl.Controls.Add(lichthi);
        }

        private void btDiemThi_Click(object sender, EventArgs e)
        {
            pnlControl.Controls.Clear();
            UC_XemDiemThi diemthi = new UC_XemDiemThi(Session);
            diemthi.Dock = System.Windows.Forms.DockStyle.Fill;
            pnlControl.Controls.Add(diemthi);
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            pnlControl.Controls.Clear();
            UC_LichThi lichthi = new UC_LichThi(Session);
            lichthi.Dock = System.Windows.Forms.DockStyle.Fill;
            pnlControl.Controls.Add(lichthi);
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            pnlControl.Controls.Clear();
            UC_XemDiemThi diemthi = new UC_XemDiemThi(Session);
            diemthi.Dock = System.Windows.Forms.DockStyle.Fill;
            pnlControl.Controls.Add(diemthi);
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frm_chonmon frm = new frm_chonmon(Session);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                string tochucthiid = frm.Value;
                frm_tracnghiem frm_tn = new frm_tracnghiem();
                frm_tn.Show();
            }
        }
    }
}
